<!DOCTYPE HTML>
<html>
<head>
    <title>移出基地</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css"/>
    <link href="/static/css/default.css" rel="stylesheet" type="text/css"/>
    <script src="/static/js/common/common.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" method="post" style="height:80%;width: 100%;overflow-x: auto;overflow-y: auto;">
<div class="mini-fit" style="margin-bottom: 45px;">
        <!-- 用户 编辑框START-->
        <div id="editform1" class="form" >
            <table class="form-table"  width="100%"  >
                    <input id = "priNum" name="priNum" class="mini-hidden" style="width: 100%;" value="${paramMap.priNum!''}"/>
                    <td  align="right" style="line-height: 30px;width:10% "><font color="#dc143c">*</font>帮教基地:</td>
                <td style="line-height: 30px;width:54%;position: relative " colspan="2">
                    <input name="jdxz"  id="jdxz" class="mini-combobox" textField="codeName" valueField="codeId" emptyText="请选择..."
                           onvaluechanged="onAzjdChanged()" value="${jdxz!''}"
                           url="/azbj/shzzgl/socialOrgInfo/getComboboxData?codeType=3_6" />
                    <input name="jdid" id="jdid" class="mini-combobox"
                           value="${jdid!''}" textField="text" valueField="id"
                           url="/azbj/azbjgl/azgzgl/getAzjdList?azType=${jdxz!''}&priNum=${priNum!''}" onvaluechanged="jdChange()">
                    </input>
                </td>
                </tr>
            </table>
        </div>
<div style="position: absolute; bottom: 0;width:100%;border-top: 1px solid #dfdfdf;line-height: 45px;text-align: center">
    <#if paramMap.isPlyc=='false'>
    <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">保存</a>
    <a class="mini-button" iconCls="fa-undo" plain="true" onclick="close()">取消</a>
    </#if>
    <#if paramMap.isPlyc=='true'>
        <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveDatapl()">批量移出基地</a>
    </#if>
</div>
</div>
</form>
<script type="text/javascript">
    mini.parse();

    var form = new mini.Form("form1");
    var priNumObj = mini.get("priNum");
    var jdxzObj = mini.get("jdxz");//安置帮教基地
    var jdidObj = mini.get("jdid");//基地id
    var count="";
    window.onload=function () {
        onAzjdChanged();
    }

    function saveData() {
        //验证非空字段
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var data = form.getData();
        data.pid=priNumObj.getValue();
        data.jdxz=jdxzObj.getValue();
        data.jdid=jdidObj.getValue();
        var jdanzhi = jdidObj.getText();
        data.jdanzhi=jdanzhi;
        var json = mini.encode(data);
        $.ajax({
            url:"/azbj/azbjgl/azgzgl/moveJdBypriNum",
            type:"post",
            data:{data:json},
            success:function(obj){
                if(obj.code ==1 ){
                    mini.alert("移除成功","成功",window.CloseOwnerWindow)
                }else if(obj.code == -1){
                    mini.alert("移除失败")
                }else if(obj.code == 8001){
                    mini.alert("目标基地人数已满，请更换基地！")
                }else if(obj.code == 4000){
                    mini.alert("帮教类型不一致！")
                }else if(obj.code == 9002){
                    mini.alert("当前基地为禁用，请更换基地");
                }else if (obj.code == 5599) {
                    mini.alert(obj.message);
                }
            }
        })
    }

    function saveDatapl() {
        //验证非空字段
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var data = form.getData();
        data.pid=priNumObj.getValue();
        data.jdxz=jdxzObj.getValue();
        data.jdid=jdidObj.getValue();
        var jdanzhi = jdidObj.getText();
        data.jdanzhi=jdanzhi;
        data.count=count;
        //data.count=count;
        var json = mini.encode(data);
        $.ajax({
            url:"/azbj/azbjgl/azgzgl/moveJdBypriNumPl",
            type:"post",
            data:{data:json},
            success:function(obj){
                if(obj.code ==1 ){
                    mini.alert("移除成功","成功",window.CloseOwnerWindow)
                }else if(obj.code == 8001){
                    mini.alert("当前移出基地已满,已成功移出:"+obj.data+"人！")
                    count=obj.data;
                }else if(obj.code == 4000){
                    mini.alert("帮教类型不一致！")
                }else if(obj.code == 9002){
                    mini.alert("当前基地为禁用，请更换基地");
                }else if (obj.code == 5599) {
                    mini.alert(obj.message);
                }
            }
        })
    }

    function onAzjdChanged(){
        var jdxzVal =  jdxzObj.getValue();
        jdidObj.setValue();
        var url = "/azbj/azbjgl/azgzgl/getAzjdList?azType="+jdxzVal+"&priNum=" + priNumObj.getValue();
        jdidObj.setUrl(url);
        jdidObj.select(0);
    }


    function close(action){
        if(window.CloseOwnerWindow){
            window.CloseOwnerWindow(action);
        }else{
            window.close();
        }
    }
</script>
</div>
</body>
</html>